package com.liyiqing.secondhandmall.memberservice.controller;

import java.util.Arrays;
import java.util.Map;

import com.liyiqing.commonservice.validator.methodgroup.AddGroup;
import com.liyiqing.commonservice.validator.methodgroup.UpdateGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.liyiqing.secondhandmall.memberservice.entity.MemberUserEntity;
import com.liyiqing.secondhandmall.memberservice.service.MemberUserService;
import com.liyiqing.commonservice.utils.PageUtils;
import com.liyiqing.commonservice.utils.R;



/**
 * 账号信息
 *
 * @author LiYiQing
 * @email 1570865668@qq.com
 * @date 2022-02-18 22:47:22
 */
@RestController
@RequestMapping("memberService/memberUser")
public class MemberUserController {
    @Autowired
    private MemberUserService memberUserService;


    /**
     * TODO 注册功能：新增账号
     */
    @RequestMapping("/insertMemberUser")
    public R insertMemberUser(@Validated({AddGroup.class}) @RequestBody MemberUserEntity memberUser){
        return memberUserService.insertMemberUser(memberUser);

    }

    /**
     * TODO 登录功能
     */


    /**
     * 根据id查询账号
     */
    @RequestMapping("/selectUserById/{id}")
    public R selectUserById(@PathVariable("id") Long id){
//		MemberUserEntity memberUser = memberUserService.getById(id);
        return memberUserService.selectUserById(id);
    }




    /**
     * 根据id修改账号信息
     */
    @RequestMapping("/updateMemberUser")
    public R updateMemberUser(@Validated({UpdateGroup.class})@RequestBody MemberUserEntity memberUser){
        return memberUserService.updateUserById(memberUser);
    }


    /**
     * 根据id删除账号
     */
    @RequestMapping("/deleteUserById/{id}")
    public R deleteUserById(@PathVariable Long id){
        memberUserService.removeById(id);
        return R.ok();
    }


    /**
     * 根据id批量删除
     */
    @RequestMapping("/deleteUsers")
    public R deleteUsers(@RequestBody Long[] ids){
		memberUserService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 查询所有账号
     */
    @RequestMapping("/selectAllMemberUser")
    public R selectAllMemberUser(){
        return memberUserService.selectAllMemberUser();
    }

}
